<?php

/**
 * User filter form base class.
 *
 * @package    maximous
 * @subpackage filter
 * @author     Mina.Gerges.Wadea
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseUserFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'role_id'                   => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Role'), 'add_empty' => true)),
      'username'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'name'                      => new sfWidgetFormFilterInput(),
      'password_request'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'password_request_token'    => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'password_request_end_date' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'token'                     => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'password'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'last_login'                => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'email'                     => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'code'                      => new sfWidgetFormFilterInput(),
      'phone'                     => new sfWidgetFormFilterInput(),
      'mobile'                    => new sfWidgetFormFilterInput(),
      'address'                   => new sfWidgetFormFilterInput(),
      'photo'                     => new sfWidgetFormFilterInput(),
      'need_check'                => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'statues'                   => new sfWidgetFormChoice(array('choices' => array('' => '', 1 => 1, 2 => 2, 3 => 3))),
      'remember_me_code'          => new sfWidgetFormFilterInput(),
      'created_at'                => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'deleted_at'                => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'best_categories_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Category')),
      'role_categories_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Category')),
      'category_list'             => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Category')),
    ));

    $this->setValidators(array(
      'role_id'                   => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Role'), 'column' => 'id')),
      'username'                  => new sfValidatorPass(array('required' => false)),
      'name'                      => new sfValidatorPass(array('required' => false)),
      'password_request'          => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'password_request_token'    => new sfValidatorPass(array('required' => false)),
      'password_request_end_date' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'token'                     => new sfValidatorPass(array('required' => false)),
      'password'                  => new sfValidatorPass(array('required' => false)),
      'last_login'                => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'email'                     => new sfValidatorPass(array('required' => false)),
      'code'                      => new sfValidatorPass(array('required' => false)),
      'phone'                     => new sfValidatorPass(array('required' => false)),
      'mobile'                    => new sfValidatorPass(array('required' => false)),
      'address'                   => new sfValidatorPass(array('required' => false)),
      'photo'                     => new sfValidatorPass(array('required' => false)),
      'need_check'                => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'statues'                   => new sfValidatorChoice(array('required' => false, 'choices' => array(1 => 1, 2 => 2, 3 => 3))),
      'remember_me_code'          => new sfValidatorPass(array('required' => false)),
      'created_at'                => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'deleted_at'                => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'best_categories_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Category', 'required' => false)),
      'role_categories_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Category', 'required' => false)),
      'category_list'             => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Category', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('user_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addBestCategoriesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.UserBestCategories UserBestCategories')
      ->andWhereIn('UserBestCategories.category_id', $values)
    ;
  }

  public function addRoleCategoriesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.UserRoleCategories UserRoleCategories')
      ->andWhereIn('UserRoleCategories.category_id', $values)
    ;
  }

  public function addCategoryListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.UserBestCategories UserBestCategories')
      ->andWhereIn('UserBestCategories.user_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'User';
  }

  public function getFields()
  {
    return array(
      'id'                        => 'Number',
      'role_id'                   => 'ForeignKey',
      'username'                  => 'Text',
      'name'                      => 'Text',
      'password_request'          => 'Number',
      'password_request_token'    => 'Text',
      'password_request_end_date' => 'Date',
      'token'                     => 'Text',
      'password'                  => 'Text',
      'last_login'                => 'Date',
      'email'                     => 'Text',
      'code'                      => 'Text',
      'phone'                     => 'Text',
      'mobile'                    => 'Text',
      'address'                   => 'Text',
      'photo'                     => 'Text',
      'need_check'                => 'Boolean',
      'statues'                   => 'Enum',
      'remember_me_code'          => 'Text',
      'created_at'                => 'Date',
      'updated_at'                => 'Date',
      'deleted_at'                => 'Date',
      'best_categories_list'      => 'ManyKey',
      'role_categories_list'      => 'ManyKey',
      'category_list'             => 'ManyKey',
    );
  }
}
